home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / patchSG0003743.idb / usr / include / ffio.h.z / ffio.h
C/C++ Source or Header  |  2001-04-12  |  58KB  |  1,943 lines

  1. /* USMID @(#) clibinc/ffio.h    92.6    09/22/99 16:30:21 */
  2.  
  3. /*
  4. *
  5. * Copyright 1997, Silicon Graphics, Inc.
  6. * All Rights Reserved.
  7. *
  8. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. * the contents of this file may not be disclosed to third parties, copied or
  10. * duplicated in any form, in whole or in part, without the prior written
  11. * permission of Silicon Graphics, Inc.
  12. *
  13. * RESTRICTED RIGHTS LEGEND:
  14. * Use, duplication or disclosure by the Government is subject to restrictions
  15. * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. * rights reserved under the Copyright Laws of the United States.
  19. */
  20. /*
  21.  *    (C) COPYRIGHT CRAY RESEARCH, INC.
  22.  *    UNPUBLISHED PROPRIETARY INFORMATION.
  23.  *    ALL RIGHTS RESERVED.
  24.  */
  25.  
  26. /*
  27.  *    FFIO definitions, macros, and prototypes
  28.  */
  29.  
  30. #ifndef _FFIO_H
  31. #define _FFIO_H
  32.  
  33. #include <clibdefs.h>
  34. #include <sys/types.h>        /* ffc_stat_s structure field declarations */
  35. #include <cray/fortio.h>    /* unum_t typedef */
  36. #if defined(__mips)
  37. #include <aio.h>
  38. #elif defined(_LITTLE_ENDIAN)
  39. /* do not include pthread.h for little endian systems */
  40. #else
  41. #include <cray/libuni.h>    /* for _LIB_UMK, used in fflistreq declaration*/
  42. #endif
  43.  
  44. /*
  45.  * read/write record processing modes
  46.  */
  47. #define PARTIAL 0
  48. #define FULL    1
  49.  
  50. /*
  51.  * Status values for sw_status
  52.  */
  53. #define FFBSY    0
  54. #define FFCNT    1
  55. #define FFEOR    2
  56. #define FFEOF    3
  57. #define FFEOD    4
  58. #define FFBOD    5
  59. #define FFERR    6
  60.  
  61. /*
  62.  * Command codes for fffcntl calls
  63.  *    Values:    0 -    reserved for FORTRAN 'get fio pointer'
  64.  *        1-99    reserved for CRI built-in layers
  65.  *        100-199    reserved for user layers
  66.  *        200-299    reserved for site layers
  67.  */
  68. #define FC_GETINFO    1
  69. #define FC_STAT        2
  70. #define FC_SETRECL    3
  71. #define FC_RECALL    4
  72. #define FC_ACPTBAD    5
  73. #define FC_SKIPBAD    6
  74. #define FC_GETTP    7
  75. #define FC_AUTOBAD    8
  76. #define FC_CHECKTP    9
  77. #define FC_ENDSP    10
  78. #define FC_STARTSP    11
  79. #define FC_CLOSEV    12
  80. #define FC_SETSP    13
  81. #define FC_ASPOLL    14    /* give recall a shot at cleanup, no wait */
  82. #define FC_SCRATCH    15    /* identify a file as a scratch file */
  83. #define FC_TSYNC    16    /* sync a tape file */
  84. #define FC_DUMPSTATS    17    /* dump intermediate layer statistics */
  85. #define FC_TPC_SDBSZ    18    /* change block size on ER90 */
  86. #define FC_IALLOC    19    /* bottom layer call ialloc */
  87. #define FC_GETLK    20    /* get file lock */
  88. #define FC_SETLK    21    /* set file lock */
  89. #define FC_SETLKW    22    /* set file lock wait */
  90. #define FC_FSTATFS    23    /* bottom layer call fstatfs */
  91. #define FC_DIOINFO    24    /* get direct info (IRIX only) */
  92. #define FC_CHECKEOV    25    /* check end-of-volume status (IRIX only) */
  93. #define FC_TSDATA    26    /* get tape status information (IRIX only) */
  94.  
  95. /*
  96.  * Mask bits for return word in FC_GETINFO fffcntl call
  97.  */
  98. #define    FFC_STRM    0x00000001    /* can handle stream I/O */
  99. #define    FFC_REC        0x00000002    /* can handle records */
  100. #define    FFC_WEOF    0x00000004    /* can represent EOF */
  101. #define    FFC_WEOD    0x00000008    /* can represent EOD (all can do) */
  102.  
  103. #define    FFC_BKSP    0x00000010    /* can handle backspace */
  104. #define    FFC_BKFIL    0x00000020    /* can handle backfile */
  105. #define    FFC_SEEKA    0x00000040    /* can seek absolute */
  106. #define    FFC_SEEKR    0x00000080    /* can seek relative */
  107. #define    FFC_SEEKE    0x00000100    /* can seek to end */
  108. #define    FFC_POSREC    0x00000200    /* can position by record number */
  109. #define    FFC_POSFIL    0x00000400    /* can position by EOF mark */
  110. #define    FFC_RWND    0x00000800    /* can rewind by seek(x,0,0) */
  111.  
  112. #define    FFC_FIXD    0x00001000    /* can do fixed len recs */
  113. #define    FFC_VAR        0x00002000    /* can do variable len recs */
  114. #define    FFC_BINARY    0x00004000    /* can do binary records */
  115. #define    FFC_CODED    0x00008000    /* can do formatted records */
  116.  
  117. #define    FFC_RDM        0x00010000    /* can do random I/O (no trunc) */
  118. #define    FFC_SEQ        0x00020000    /* can do sequential I/O */
  119. #define    FFC_ASYNC    0x00040000    /* can do asynchronous I/O */
  120. #define    FFC_WRTRUNC    0x00080000    /* write implies truncation */
  121.  
  122. #define    FFC_NOTRN    0x00100000    /* Does no transformation on data */
  123.                     /* hence, 'backdoor' ops can be OK */
  124. #define    FFC_BCKDOOR    0x00200000    /* Can handle O_SSD flag on open call */
  125. #define    FFC_SKIPBAD    0x00400000    /* Can skip bad data */
  126. #define    FFC_NOCLOSE    0x00800000    /* Don't try to close layer on abort */
  127. #define    FFC_CANLISTIO    0x01000000    /* The layer has a listio entry */
  128. #define    FFC_CANSYLISTIO    0x02000000    /* The layer has a listio entry that  */
  129.                     /* is capable of limited listio */
  130.  
  131. /*
  132.  * Command codes for POS calls
  133.  */
  134. #define FP_GETPOS    1    /* get position of file */
  135. #define FP_SETPOS    2    /* set position of file */
  136. #define FP_BSEEK    3    /* seek to bit position */
  137. #define FP_BKSP        4    /* back up one record (BACKSPACE) */
  138. #define FP_BKFIL    5    /* back up one file (BACKFILE) */
  139. #define FP_GETREC    6    /* Get current record number */
  140. #define FP_SETREC    7    /* Set position to specified record number */
  141. #define FP_SKIPF    8    /* Skip file (SKIPF) */
  142. #define FP_SETTP    9    /* set position of tape file (SETTP) */
  143. #define FP_POS0        10    /* "position to current position" */
  144. #define FP_RSEEK    11    /* relative seek */
  145. #define FP_SKIPTPMK    12    /* skip tape mark */
  146. #define FP_GABS        13    /* get absolute position */
  147. #define FP_SABS        14    /* set absolute position */
  148. #define FP_GETTAPEPOS    15    /* get tape position (IRIX only) */
  149. #define FP_SETTAPEPOS    16    /* set tape position (IRIX only) */
  150.  
  151. /*
  152.  * Codes used to indicate direction/meaning for some positioning requests
  153.  */
  154. #define FP_TPOS_ABS    0    /* absolute */
  155. #define FP_TPOS_FORW    1    /* forward */
  156. #define FP_TPOS_BACK    2    /* backwards */
  157.  
  158. /*
  159.  * Argument values for FC_AUTOBAD fffcntl request
  160.  */
  161. #define AUTO_SKIP    1    /* skip 1 block of bad data */
  162. #define AUTO_ACPT    2    /* accept bad data */
  163. #define AUTO_SKIPALL    3    /* skip all bad data */
  164.  
  165. /*
  166.  * Flag values for FC_SCRATCH fffcntl request status word.
  167.  */
  168. #define SCR_SINGLELINK    1    /* file is regular and not a linked file */
  169. #define SCR_UNLINKED    2    /* an unlink() successfully deleted the file */
  170. #define    SCR_NOFLUSH    4    /* ffclose() buffer flushing suppressed */
  171.  
  172. /*
  173.  * Return the I/O status from an operation.
  174.  */
  175. #define FFSTAT(io_sw)        ((io_sw).sw_stat)
  176.  
  177. /*
  178.  *    Status return:  This structure is used in all internal calls to return
  179.  *    status.  The first word is made compatible with the iosw for use
  180.  *    with async I/O.
  181.  */
  182. struct ffsw
  183.     {
  184.     unsigned int    sw_flag:1;
  185.     unsigned int    sw_error:31;
  186. #ifdef    __mips
  187.     size_t        sw_count;
  188. #else
  189.     unsigned int    sw_count:32;
  190. #endif
  191.     unsigned int    sw_stat:16;    /* FFCNT, etc. */
  192. #if    defined(_WORD32) || defined(__mips) || defined(_LITTLE_ENDIAN)
  193.     int        sw_user:32;    /* For user layer storage */
  194. #else
  195.     int        sw_user:48;    /* For user layer storage */
  196. #endif
  197. #if    defined(_ADDR64) || defined(__mips) || defined(_LITTLE_ENDIAN)
  198.     void        *sw_iptr;    /* pointer to layer data */
  199.     void        *sw_sptr;    /* pointer to status chain, if used. */
  200. #else
  201.     int        sw_iptr:32;    /* pointer to layer data */
  202.     int        sw_sptr:32;    /* pointer to status chain, if used. */
  203. #endif
  204.     int        sw_rsv1;    /* may need later.  Save space now */
  205. #ifdef    __mips
  206.     aiocb_t        aiocbp;
  207. #endif
  208. #ifdef    _EXTRA_FFSW_STUFF
  209.     _EXTRA_FFSW_STUFF        /* for internal Cray applications use */
  210. #endif
  211.     };
  212.  
  213. /*
  214.  *    fffcntl FC_GETINFO structure
  215.  */
  216. struct ffc_info_s
  217.     {
  218.     long    ffc_flags;    /* flag word */
  219.     int    ffc_gran;    /* minimum granularity, no. bits in smallest */
  220.                 /* I/O possible. (bits/bytes/words) */
  221.     int    ffc_reclen;    /* Record length (in bits) */
  222.     int    ffc_fd;        /* Lowest level file desc, -1 if invalid */
  223.     int    ffc_poslen:16;    /* GETPOS/SETPOS pos array length */
  224. #if    defined(_WORD32) || defined(__mips) || defined(_LITTLE_ENDIAN)
  225.     int    unused1:16;    /* reserved */
  226. #else
  227.     int    unused1:48;    /* reserved */
  228. #endif
  229.     int    unused2;    /* reserved */
  230.     };
  231.  
  232. /*
  233.  *    fffcntl FC_SKIPBAD or FC_ACPTBAD structure
  234.  */
  235. struct ffc_baddata_s
  236.     {
  237.     int    ffc_termcnd;    /* position after handling bad data */
  238.     int    ffc_blocks;    /* number of blocks skipped */
  239.     int    ffc_bytes;    /* number of bytes accepted */
  240.     int    ffc_maxflag;    /* 1 if maximum number of words to accept */
  241.     int    ffc_maxwords;    /* maximum number of words to accept */
  242.     long    ffc_uda;    /* address of area to store data */
  243.     int    unused1;    /* reserved */
  244.     int    unused2;    /* reserved */
  245.     };
  246.  
  247. /*
  248.  *    fffcntl FC_GETTP structure
  249.  */
  250. struct ffc_gettp_s
  251.     {
  252.     int    ffc_glen;    /* number of words to copy to ffc_pa */
  253.     int    ffc_synch;    /* 1 = synch, 0 = do not. Only after write */
  254. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  255.     long long    *ffc_pa;/* info copied here */
  256. #else
  257.     long    *ffc_pa;    /* info copied here */
  258. #endif
  259.     int    unused1;    /* reserved */
  260.     int    unused2;    /* reserved */
  261.     };
  262.  
  263. /*
  264.  *    fffcntl FC_CHECKTP structure
  265.  */
  266. struct ffc_chktp_s
  267.     {
  268.     int    stat;        /* status of tape */
  269.     int    libblk;        /* Number of blocks in library */
  270.     int    unused1;    /* reserved */
  271.     int    unused2;    /* reserved */
  272.     };
  273.  
  274. /*
  275.  *    fffcntl FC_CHECKEOV structure
  276.  */
  277. struct ffc_chkev_s
  278.     {
  279.     int    stat;        /* status of tape: 1 = at eov */
  280.     int    bufblk;        /* Number of buffered whole blocks */
  281.     size_t    bufbytes;    /* number of bytes unwritten from last record
  282.                    on the tape */
  283.     int    unused1;    /* reserved */
  284.     int    unused2;    /* reserved */
  285.     };
  286.     
  287. /*
  288.  *    fffcntl FC_STAT structure
  289.  *
  290.  *    This is a copy of the stat structure defined in <sys/stat.h>.
  291.  *    Matches stat structure for:
  292.  *
  293.  *            UNICOS 8.0
  294.  *            UNICOS-MAX 1.0
  295.  *            Solaris 5.3
  296.  */
  297. #ifdef    _UNICOS
  298.  
  299. struct    ffc_stat_s
  300.     {
  301.     dev_t    st_dev;
  302.     ino_t    st_ino;
  303.     mode_t     st_mode;
  304.     nlink_t    st_nlink;
  305.     uid_t     st_uid;
  306.     gid_t     st_gid;
  307.     dev_t    st_rdev;
  308.     off_t    st_size;
  309.     time_t    st_atime;
  310.     long    st_spare1;        /* Reserved for microsec time stamps */
  311.     time_t    st_mtime;
  312.     long    st_spare2;        /* Reserved for microsec time stamps */
  313.     time_t    st_ctime;
  314.     long    st_spare3;        /* Reserved for microsec time stamps */
  315.     _SHORTPAD
  316.     unsigned short    st_acid;    /* Accounting id */
  317. #if    defined(_CRAY1) || defined(_CRAYMPP)
  318.     long    st_count;        /* Reference count */
  319.     off_t    st_msize;        /* Modification size for signature */
  320. #endif /* _CRAY1 || _CRAYMPP */
  321.     unsigned int st_msref : 1,    /* Modification signature referenced */
  322.              st_ms    :31,    /* Modification signature */
  323.              st_gen   :32;    /* Generation number */
  324. #if    defined(_CRAY1) || defined(_CRAYMPP)
  325. /*18*/
  326.     long    st_blocks;        /* #of sectors allocated to file */
  327.     long    st_blksize;        /* Optimal small I/O xfer size (bytes)*/
  328.     long    st_oblksize;        /* Optimal large I/O xfer size (bytes)*/
  329.     long    st_allocf;        /* Allocation flags */
  330.     long    st_cblks;        /* Cluster blocks (Cray-YMP) */
  331.     long    st_cbits;        /* Cluster bits */
  332.     long    st_param[8];        /* 8-pack track/sector addresses */
  333.     long    st_spareparam[4];    /* Reserved for additional pack */
  334. #endif /* _CRAY1 || _CRAYMPP */
  335. /*36*/
  336.     /* data migration fields */
  337.     _SHORTPAD
  338.     unsigned short    st_dm_mode;    /* actual file mode */
  339.     unsigned int
  340.         st_dm_port  : 3,    /* migrated file daemon port */
  341.         st_dm_state : 5,    /* migrated file state */
  342.         st_dm_status: 56;    /* migrated file status flags */
  343.     long    st_dm_mid;        /* migrated file machine id */
  344.     long    st_dm_key;        /* migrated file key */
  345.  
  346. /*40*/
  347.     /* security fields */
  348.     unsigned int        : 62,
  349.         st_hasacl   : 1,    /* File has an ACL */
  350.         st_hascomps : 1;    /* File has compartments */
  351.     _SHORTPAD
  352.     short    st_slevel;        /* file level */
  353.     _SHORTPAD
  354.     short    st_secflg;        /* security flags */
  355.     _SHORTPAD
  356.     short    st_intcls;        /* integrity class */
  357.     _SHORTPAD
  358.     short    st_intcat;        /* integrity category */
  359.  
  360. /*45*/
  361.     long    st_site;        /* site field from inode */
  362.     long    st_nindir;        /* # of indirect extent blocks */
  363.     long    st_resv_pad[6];        /* reserved pad space to 53 words */
  364.     };
  365.  
  366. #elif    defined(_SOLARIS)
  367.  
  368. #include <sys/time.h>
  369.  
  370. struct    ffc_stat_s {
  371.     dev_t    st_dev;
  372.     long    st_pad1[3];
  373.     ino_t    st_ino;
  374.     mode_t    st_mode;
  375.     nlink_t st_nlink;
  376.     uid_t     st_uid;
  377.     gid_t     st_gid;
  378.     dev_t    st_rdev;
  379.     long    st_pad2[2];
  380.     off_t    st_size;
  381.     long    st_pad3;
  382.     timestruc_t st_atim;
  383.     timestruc_t st_mtim;
  384.     timestruc_t st_ctim;
  385.     long    st_blksize;
  386.     long    st_blocks;
  387.     char    st_fstype[16 /* == _ST_FSTYPSZ */ ];
  388.     long    st_pad4[8];
  389.     };
  390.  
  391. #elif    defined(__mips)
  392. #include <sys/stat.h>
  393. #ifdef    _TIMESTRUCT_T
  394. #define _TIMESTRUCT_FFIO timestruct_t
  395. #else
  396. #define _TIMESTRUCT_FFIO timespec_t
  397. #endif
  398. struct    ffc_stat_s {
  399.     dev_t   st_dev;
  400.     long    st_pad1[3];     /* reserved for network id */
  401.     ino_t   st_ino;
  402.     mode_t  st_mode;
  403.     nlink_t st_nlink;
  404.     uid_t   st_uid;
  405.     gid_t   st_gid;
  406.     dev_t   st_rdev;
  407.     long    st_pad2[2];     /* dev and off_t expansion */
  408.     off_t   st_size;
  409.     long    st_pad3;        /* future off_t expansion */
  410.     _TIMESTRUCT_FFIO st_atim;
  411.     _TIMESTRUCT_FFIO st_mtim;
  412.     _TIMESTRUCT_FFIO st_ctim;
  413.     long    st_blksize;
  414.     blkcnt_t st_blocks;
  415.     char    st_fstype[_ST_FSTYPSZ];
  416.     long    st_pad4[8];     /* expansion area */
  417. };
  418. #elif    defined(_LITTLE_ENDIAN)
  419. #include <sys/stat.h>
  420. struct    ffc_stat_s {
  421.     dev_t    st_dev;
  422.     unsigned short    st_pad1[1];
  423.     ino_t    st_ino;
  424.     mode_t    st_mode;
  425.     nlink_t st_nlink;
  426.     uid_t     st_uid;
  427.     gid_t     st_gid;
  428.     dev_t    st_rdev;
  429.     unsigned short    st_pad2[1];
  430.     off_t    st_size;
  431.     long    st_blksize;
  432.     long    st_blocks;
  433.     time_t    st_atim;
  434.     unsigned long    unused1[1];
  435.     time_t    st_mtim;
  436.     unsigned long    unused2[1];
  437.     time_t    st_ctim;
  438.     unsigned long    unused3[1];
  439.     unsigned long    unused4[1];
  440.     unsigned long    unused5[1];
  441.     };
  442.  
  443. #endif    /* __mips */
  444.  
  445. /*
  446.  *    fffcntl FC_IALLOC structure
  447.  */
  448. struct ff_ialloc_struct 
  449.     {
  450.     long    ia_nb;
  451.     int    ia_flag;
  452.     int    ia_part;
  453.     int    ia_avl;
  454.     int    ia_ret;
  455.     int    ia_before;
  456.     };
  457. /*
  458.  *    FP_SKIPF structure
  459.  */
  460. struct ffp_skipf_s
  461.     {
  462.     int    ffp_nfil;    /* number of files to skip (input and output) */
  463.     int    ffp_nrec;    /* number of records skipped (optional output)*/
  464.     };
  465.  
  466. /*
  467.  *    FP_SETTP structure
  468.  */
  469. struct ffp_settp_s
  470.     {
  471.     int        ffp_nbs_p;    /* forward, backward or absolute nb */
  472.     long        ffp_nb;        /* number of blocks (always positive) */
  473.     int        ffp_nvs_p;    /* forward, backward or absolute nv */
  474.     int        ffp_nv;        /* number of volumes (always positive) */
  475. #if    defined(__mips)
  476.     __int64_t    ffp_vi;        /* volume identifier */
  477. #elif    defined(_LITTLE_ENDIAN)
  478.     long long    ffp_vi;        /* volume identifier */
  479. #else
  480.     long        ffp_vi;        /* volume identifier */
  481. #endif
  482.     int        unused1;    /* reserved */
  483.     int        unused2;    /* reserved */
  484.     };
  485.     
  486. /*
  487.  *    FP_SKIPTPMK structure
  488.  */
  489. struct ffp_skiptpmk_s
  490.     {
  491.     int    ffp_ntpmk;    /* number of tpmks to skip (input and output) */
  492.     int    unused1;    /* reserved */
  493.     };
  494.  
  495. /*
  496.  *    FP_GABS and FP_SABS structure
  497.  */
  498.     struct ffp_abs
  499.     {
  500. #if defined(__mips)
  501.     __int64_t    ffp_absaddr;
  502. #elif    defined(_LITTLE_ENDIAN)
  503.     long long    ffp_absaddr;
  504. #else
  505.     long    ffp_absaddr;
  506. #endif
  507.     int    ffp_partition;
  508.     int    ffp_filesec;
  509.     int    ffp_datablock;
  510.     };
  511.  
  512. /*
  513.  *    FP_GETTAPEPOS and FP_SETTAPEPOS structures
  514.  */
  515.     struct ffp_tapepos
  516.     {
  517.     int    ffp_type;
  518.     int    ffp_blockno;
  519. #if    defined(__mips)
  520.     __int64_t    ffp_vsn;
  521. #elif    defined(_LITTLE_ENDIAN)
  522.     long long    ffp_vsn;
  523. #else
  524.     long    ffp_vsn;
  525. #endif
  526.     int    ffp_resvd[4];
  527.     };
  528.  
  529. /*
  530.  *    fflistio request structure, similar to def in <sys/listio.h>
  531.  */
  532.  
  533. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  534. struct    fflistreq
  535.     {
  536.     int    li_opcode;        /* operation code */
  537.     int    li_drvr:32,        /* driver dependent */
  538.         li_flags:32;        /* request flags */
  539.     off_t    li_offset;        /* starting byte offset */
  540.     int    li_fildes;        /* file descriptor (returned by ffopen)*/
  541.     char    *li_buf;        /* buffer address */
  542.     size_t    li_nbyte;        /* bytes per stride count */
  543.     struct ffsw *li_status;        /* status structure */
  544.     int    li_signo;        /* signal to send upon completion */
  545.     int    li_nstride;        /* number of strides */
  546.     off_t    li_filstride;        /* file stride length in bytes */
  547.     size_t    li_memstride;        /* buffer stride length in bytes */
  548.     struct fdinfo *li_ffioptr;    /* for use by library routines */
  549.     };
  550. #else
  551. struct    fflistreq
  552.     {
  553.     int    li_opcode;        /* operation code */
  554.     int    li_drvr:32,        /* driver dependent */
  555.         li_flags:32;        /* request flags */
  556.     long    li_offset;        /* starting byte offset */
  557.     int    li_fildes;        /* file descriptor (FFIO pointer) */
  558.     char    *li_buf;        /* buffer address */
  559.     long    li_nbyte;        /* bytes per stride count */
  560.     struct ffsw *li_status;        /* status structure */
  561.     int    li_signo;        /* signal to send upon completion */
  562.     int    li_nstride;        /* number of strides */
  563.     long    li_filstride;        /* file stride length in bytes */
  564.     long    li_memstride;        /* buffer stride length in bytes */
  565. #ifdef    _LIB_UMK
  566. #ifndef _CRAY1
  567.     int    li_remote_vpe;        /* distio vpe number */
  568.     int    li_pad[3];        /* mpp extensions */
  569. #endif
  570. #endif
  571.     };
  572. #endif
  573.  
  574. #ifdef    _LIB_INTERNAL        /* defs below are not for user consumption */
  575.  
  576. #include <cray/portdefs.h>
  577.  
  578. #ifndef _TRUE
  579. #define _TRUE 1
  580. #endif
  581. #ifndef _FALSE
  582. #define _FALSE 0
  583. #endif
  584.  
  585. #define NO    0
  586. #define NONE    0
  587. #define YES    1    /* it is important that this is 1 */
  588.  
  589. /*
  590.  * Change this anytime the format of the environment variables changes.
  591.  */
  592. #define ASG_VERSION 1
  593.  
  594. #if    defined(_WORD32) || defined(__mips) || defined(_LITTLE_ENDIAN)
  595. #define MAGIC_ID 0x2d464443    /* '-FDC' only 4 chars per int */
  596. #else
  597. #define MAGIC_ID '--*FDC--'
  598. #endif
  599.  
  600. /*
  601.  * The following is a macro to change a CAL symbol declaration into a
  602.  * value usable by C.
  603.  */
  604. #define _VALUE(xtern)    ((int)(&(xtern)))
  605.  
  606. /*
  607.  * General directions
  608.  *    These are the constants that are used to keep track of the state of
  609.  *    the I/O.
  610.  */
  611. #define READIN    1    /* last op was READ */
  612. #define WRITIN    2    /* last op was WRITE */
  613. #define POSITIN    4    /* last op was POSITION */
  614.  
  615. /*
  616.  * Record Translation classes
  617.  *    Note: All of the conversion types for IBM and VMS can be grouped into
  618.  *    two classes.  The Fixed length record type, and the Variable
  619.  *    length record type.  These types differ within the broad
  620.  *    group according to the existence of blocking, control words,
  621.  *    and padding.
  622.  *
  623.  * When adding new classes, be sure to look in libu/ffio/fxrmisc.c and update
  624.  *    ownopen[] and in fxrmain.c update _recfm_tab[]
  625.  */
  626. #define CLASS_END    0    /* End of chain marker. This is a dummy layer */
  627.                 /* that is always tacked on the end of spec. */
  628.                 /* It selects an appropriate handler. */
  629.                 /* depending on the device. */
  630. #define CLASS_SYSCALL    1    /* handlers for UNIX/stream record model */
  631. #define CLASS_NULL    2    /* explicit NULL layer, does nothing */
  632. #define CLASS_SYSTEM    3    /* same as End of Chain, above */
  633. #define CLASS_COS    4    /* COS blocking */
  634. #define CLASS_BMX    5    /* TAPE handlers */
  635. #define CLASS_F        6    /* FIXED length, no control words */
  636. #define CLASS_V        7    /* variable length, control words */
  637.                 /* as prefixes only */
  638. #define CLASS_TEXT    8    /* records terminated by 'special character' */
  639. #define CLASS_X        9    /* records with control words as both */
  640.                 /* prefix and suffix on each record */
  641. #define CLASS_CDC    10    /* CDC class */
  642. #define CLASS_SDS    11    /* SDS handlers */
  643. #define CLASS_MR    12    /* memory resident layer */
  644. #define CLASS_TRACE    13    /* TRACE handlers.  Debug tool for 1 file */
  645. #define CLASS_USER    14
  646. #define CLASS_SITE    15
  647. #define CLASS_ERROR    16    /* error layer */
  648. #define CLASS_FD    17    /* user specified file descriptor */
  649. #define CLASS_BLX    18    /* blank expand/compress layer */
  650. #define CLASS_CACHE    19    /* cache layer */
  651. #define CLASS_ER90B    20    /* ER90 byte-stream layer */
  652. #define CLASS_BUFA    21    /* bufa layer */
  653. #define CLASS_CACHEA    22    /* cachea layer */
  654. #define CLASS_EVENT    23    /* event layer */
  655. #define CLASS_LOCK    24    /* lock layer - CRI internal use */
  656. #define CLASS_GLOBAL    25    /* global layer (mpp systems only) */
  657. #define CLASS_F77    26    /* f77 layer */
  658. #define CLASS_TMF    27    /* tmf layer */
  659. #define CLASS_CMP    28    /* compression layer */
  660.  
  661. #define CLASS_USER0    30
  662. #define CLASS_USER1    31
  663. #define CLASS_USER2    32
  664. #define CLASS_USER3    33
  665. #define CLASS_USER4    34
  666. #define CLASS_USER5    35
  667. #define CLASS_USER6    36
  668. #define CLASS_USER7    37
  669. #define CLASS_USER8    38
  670. #define CLASS_USER9    39
  671.  
  672. #define NUM_CLASSES    40
  673.  
  674. /*
  675.  * Get definitions of error numbers.
  676.  */
  677. #include <liberrno.h>
  678.  
  679. /*
  680.  * Status returns
  681.  */
  682. #define ERR    -1
  683.  
  684. /*
  685.  * ===== Define operation(s) on bit pointers =====
  686.  */
  687.  
  688. /*
  689.  * typedefs
  690.  */
  691.  
  692. /*
  693.  * The bitptr is the basic pointer for use by the FDC routines.
  694.  *
  695.  * For CRAY-2 and CX/CEA machines, it is a word pointer shifted
  696.  * left 6 bits, with the bit offset in the lower 6 bits.
  697.  *
  698.  * For the CRAY-T3D, CRAY-T3E, and MIPS 64-bit architectures it is a character
  699.  * pointer shifted left 3 bits, with the bit offset in the lower 3 bits.
  700.  *
  701.  * For 32-bit architectures, it is a 64 bit word that is a 32 bit
  702.  * character pointer shifted left 3 bits, with the bit offset in
  703.  * the lower 3 bits.
  704.  */
  705.  
  706. #ifdef    __mips
  707. typedef __int64_t bitptr;    
  708. #elif    defined(_WORD32) || defined(_LITTLE_ENDIAN)
  709. typedef long long bitptr;
  710. #else
  711. typedef long bitptr;
  712. #endif
  713.  
  714. /*
  715.  * GET_BPTR()
  716.  *    Get the raw value of a bit pointer into a word.
  717.  */
  718. #define GET_BPTR(value,bit_ptr)    (value) = (bit_ptr)
  719.  
  720. /*
  721.  * SET_BPTR()
  722.  *    Set a bit pointer to a value
  723.  */
  724. #define SET_BPTR(bit_ptr,value)    (bit_ptr) = (value)
  725.  
  726. /*
  727.  * INC_BPTR()
  728.  *    increment a bit pointer.
  729.  */
  730. #define INC_BPTR(bit_ptr,inc)    ((bitptr)(bit_ptr) + (bitptr)(inc))
  731.  
  732. /*
  733.  * SUBT_BPTR(bptr1, bptr2)
  734.  *    Subtract bptr2 from bptr1 and return a number of bits
  735.  */
  736. #define SUBT_BPTR(bptr1, bptr2)    ((bitptr)(bptr1) - (bitptr)(bptr2))
  737.  
  738. /*
  739.  * BPTR2WP()
  740.  *    Convert a bit pointer to a C word pointer
  741.  */
  742. #ifdef    _WORD32 
  743. #define BPTR2WP(bptr)        ((long *)(((long)((bitptr)(bptr) >> 3)) & ~0x3))
  744. #elif    defined (_CRAYMPP) || (_MIPS_SZLONG == 64)
  745. #define BPTR2WP(bptr)        ((long *)(((long)(bptr) >> 3) & ~0x7))
  746. #else
  747. #define BPTR2WP(bptr)        ((long *)((long)(bptr) >> 6))
  748. #endif
  749.  
  750. /*
  751.  * BPTR2CP()
  752.  *    Convert a bit pointer to a C character pointer
  753.  */
  754. #if    defined (_CRAYMPP) || defined (_WORD32) || defined(__mips) || \
  755.     defined(_LITTLE_ENDIAN)
  756. #define BPTR2CP(bptr)        ((char *)((long)((bitptr)(bptr) >> 3)))
  757. #else
  758. #define BPTR2CP(bptr) \
  759.     ((char *)(_dshiftr((long)(bptr), (long)(bptr), 6) & 0xe3ffffffffffffff))
  760. #endif
  761.  
  762. /*
  763.  * WPTR2BP()
  764.  *    Convert a C word pointer to a bit ptr
  765.  */
  766. #if    defined (_CRAYMPP) || defined (_WORD32) || defined(__mips) || \
  767.     defined(_LITTLE_ENDIAN)
  768. #define WPTR2BP(wp)        (((bitptr)((long)((char *)(wp)))) << 3)
  769. #else
  770. #define WPTR2BP(wp)        ((long)(((long)((char *)(wp))) << 6))
  771. #endif
  772.  
  773. /*
  774.  * CPTR2BP()
  775.  *    Convert a C character pointer to a bit ptr
  776.  */
  777. #if    defined (_CRAYMPP) || defined (_WORD32) || defined(__mips) || \
  778.     defined(_LITTLE_ENDIAN)
  779. #define CPTR2BP(cptr)        (((bitptr)(long)(char *)(cptr)) << 3)
  780. #else
  781. #define CPTR2BP(cptr)        ((long)_dshiftl((long)(cptr), (long)(cptr), 6))
  782. #endif
  783.  
  784. /*
  785.  * BPTR2DWP()
  786.  *      Convert a bit ptr to a 64-bit-word ptr
  787.  */
  788. #ifdef    _WORD32
  789. #define BPTR2DWP(bptr)          ((long *)(((long)((bitptr)(bptr) >> 3)) & ~0x7))
  790. #elif    defined (_CRAYMPP) || (_MIPS_SZLONG == 64)
  791. #define BPTR2DWP(bptr)           ((long *)(((long)(bptr) >> 3) & ~0x7))
  792. #else
  793. #define BPTR2DWP(bptr)        ((long *)((long)(bptr) >> 6))
  794. #endif
  795.  
  796. /*
  797.  * BPBITOFF(bitptr)
  798.  *    Return the bit offset within the current word.
  799.  */
  800. #ifdef    _WORD32 
  801. #define BPBITOFF(bptr)        (long) ((bitptr)(bptr) & 0x1fLL)
  802. #else
  803. #define BPBITOFF(bptr)        ((long)(bptr) & 0x3f)
  804. #endif
  805.  
  806. /*
  807.  * BPDWBITOFF(bitptr)
  808.  *    Return the bit offset within the current 64-bit word.
  809.  */
  810. #ifdef    _WORD32
  811. #define BPDWBITOFF(bptr)          (long) ((bitptr)(bptr) & 0x3fLL)
  812. #else
  813. #define BPDWBITOFF(bptr)          ((long)(bptr) & 0x3f)
  814. #endif
  815.  
  816. /*
  817.  * NUMARG()
  818.  *    Get the number of words passed in the argument list of the current
  819.  *    function.
  820.  */
  821. #ifdef    _UNICOS
  822. #define NUMARG(x)    x = _numargs()
  823. #endif
  824.  
  825. /*
  826.  * Get the IO info block for a file descriptor
  827.  */
  828. #if    !defined(__mips) && !defined(_LITTLE_ENDIAN)
  829. #define GETIOB(x) (struct fdinfo *)(x)
  830. #else
  831. extern struct fdinfo *_cnvrt2fdinfo(int _fd);
  832. #define GETIOB(x) _cnvrt2fdinfo(x)
  833. #endif
  834.  
  835. /*
  836.  * XRCALL is a simple macro that allows control of the mechanism that
  837.  * handles the function pointer references.  It also allows us to
  838.  * insert debugging code at build time.
  839.  */
  840. #if    defined(DEBUG) && !defined(__mips) && !defined(_LITTLE_ENDIAN)
  841. #define XRCALL(fio,ptrname)    _xrtrace((fio), (fio)->xr.ptrname,#ptrname,
  842. #else
  843. #define XRCALL(fio,ptrname)    (fio)->xr.ptrname(
  844. #endif
  845. /*
  846.  * Add check for fdinfo pointer.
  847.  */
  848. #define CHECK_FIOPTR(fio, stat)                        \
  849.         {                            \
  850.         if (fio == (struct fdinfo *)0L || fio == (struct fdinfo *)-1L || \
  851.             fio->magic != MAGIC_ID)                \
  852.             {                        \
  853.             errno = FDC_ERR_BADPTR;                \
  854.             ERETURN(stat, FDC_ERR_BADPTR, 0);        \
  855.             }                        \
  856.         }
  857.  
  858. /*
  859.  * Debugging stuff
  860.  */
  861. #define FDCTRACE(bit) ((__fdctrace_enable & (bit)) != 0)
  862.  
  863. /*
  864.  * bit defines for debug output
  865.  */
  866. #define TRACE_CALLS    0x001
  867. #define TRACE_STATUS    0x002
  868. #define TRACE_ASG    0x004
  869. #define TRACE_OPEN    0x008
  870. #define TRACE_COS    0x010
  871. #define TRACE_SDSIO    0x020
  872. #define TRACE_WA    0x040
  873. #define TRACE_CACHE    0x080
  874. #define TRACE_SYS    0x100
  875.  
  876. /*
  877.  * IS_RESERVED_FC evaluates to:
  878.  *    1 if the fffcntl function code is one reserved for site or user layers.
  879.  *    0 otherwise.
  880.  */
  881. #define IS_RESERVED_FC(x)    (100 <= (x) && (x) <= 299)
  882.  
  883. /*
  884.  * DUMP_IOB dumps out the IOB in human readable format for
  885.  * debugging.  It is conditionally compiled and is a no-op
  886.  * in normal use.
  887.  */
  888. #if    defined(DEBUG) && !defined(__mips) && !defined(_LITTLE_ENDIAN)
  889. #define DUMP_IOB(fio)                            \
  890.     {                                \
  891.     if (FDCTRACE(TRACE_OPEN))                    \
  892.         {                            \
  893.         _xrt_putf("DUMP_IOB: fio=%o B %d - rfd=%o B %d, nfio=%o\n",\
  894.             fio, fio, (fio)->realfd, (fio)->realfd,        \
  895.             (fio)->fioptr);                    \
  896.         _xrt_putf("DUMP_IOB:\trtype=%d, mxr=%d, mbs=%d\n",    \
  897.             (fio)->rtype,                    \
  898.             (fio)->maxrecsize, (fio)->maxblksize);        \
  899.         _xrt_putf("DUMP_IOB:\tbase=%o, bufsize=%o\n",        \
  900.             (fio)->_base, (fio)->_ffbufsiz);        \
  901.         }                            \
  902.     }
  903.  
  904. #define GTRACEBACK()    TRBK()
  905.  
  906. #define EQ ==
  907. #define NE !=
  908. #define LT <
  909. #define GT >
  910. #define LE <=
  911. #define GE >=
  912. #define SANITYCHK(aarg,rel,bbarg)                    \
  913.         if (aarg rel bbarg)                    \
  914.             {                        \
  915.             _xrt_putf("SANITY CHECK: %s %s %s !!\n",    \
  916.                 #aarg, #rel, #bbarg);            \
  917.             _xrt_putf("%s=%d %16x, %s=%d %16x\n",        \
  918.                 #aarg,aarg,aarg,#bbarg,bbarg,bbarg);    \
  919.             GTRACEBACK();                    \
  920.             exit(1);                    \
  921.             }
  922.  
  923. #define BUFCHK(fio,bits)                        \
  924.             {                        \
  925.             char *BCXbuflim, *BCXcurdat, *BCXptr, *BCXbase;    \
  926.                                     \
  927.             BCXbase = BPTR2CP((fio)->_base);        \
  928.             BCXptr = BPTR2CP((fio)->_ptr);            \
  929.             SANITYCHK(BCXptr,LT,BCXbase);            \
  930.             BCXbuflim = BPTR2CP((fio)->_base) + (fio)->_ffbufsiz; \
  931.             BCXcurdat = BPTR2CP((fio)->_ptr) + ((bits) >> 3); \
  932.             SANITYCHK(BCXcurdat,GT,BCXbuflim);        \
  933.             }
  934.             
  935. #else
  936. #define DUMP_IOB(fio)        /* no-op */
  937. #define SANITYCHK(a,rel,b)    /* no-op */
  938. #define BUFCHK(fio,bits)    /* no-op */
  939. #endif
  940.  
  941. /*
  942.  * READBLK()
  943.  *    Read one block from the next lower layer.
  944.  *    Data is read in at fio->_ptr.
  945.  */
  946. #define READBLK(retval,fio,nbytes,stat,fulp,ubc)            \
  947.             {                        \
  948.             struct fdinfo *RBllfio;                \
  949.                                     \
  950.             SANITYCHK((nbytes),LT,0);            \
  951.             RBllfio = (fio)->fioptr;            \
  952.             retval = XRCALL(RBllfio,readrtn)        \
  953.                     (RBllfio), /* fd of nxt lvl */    \
  954.                     (fio)->_ptr,            \
  955.                     (nbytes),            \
  956.                     (stat),                \
  957.                     (fulp),                \
  958.                     (ubc));                \
  959.             (fio)->_cnt = 0;                \
  960.             if (retval > 0)                    \
  961.                 {                    \
  962.                 (fio)->_cnt = (retval << 3) - *(ubc);    \
  963.                 }                    \
  964.             }
  965.  
  966. /*
  967.  * WRITEBLK()
  968.  *    Write one block from the buffer to the next lower layer
  969.  */
  970. #define WRITEBLK(retval,fio,nbytes,stat,fulp,ubc)            \
  971.             {                        \
  972.             struct fdinfo *WBllfio;                \
  973.                                     \
  974.             SANITYCHK((nbytes),LT,0);            \
  975.             WBllfio = (fio)->fioptr;            \
  976.             retval = XRCALL(WBllfio, writertn)        \
  977.                     (WBllfio),/* fd of nxt lvl */    \
  978.                     (fio)->_base, /* addr of buf */    \
  979.                     (nbytes),            \
  980.                     (stat),                \
  981.                     (fulp),                \
  982.                     (ubc));                \
  983.             if ((retval) >= 0)                \
  984.                 {                    \
  985.                 (fio)->_cnt = 0;            \
  986.                 (fio)->_ptr = (fio)->_base;        \
  987.                 (fio)->segbits = 0;            \
  988.                 }                    \
  989.             }
  990.  
  991. /*
  992.  * SKIP_BITS()
  993.  * on reading, skip the given number of bits by adjusting counters
  994.  */
  995. #define SKIP_BITS(xfio,xnbits)                        \
  996.                 {                    \
  997.                 register int SKBtemp;            \
  998.                 SKBtemp = (xnbits);            \
  999.                 SET_BPTR((xfio)->_ptr,            \
  1000.                     INC_BPTR((xfio)->_ptr,SKBtemp)); \
  1001.                 (xfio)->segbits -= SKBtemp;        \
  1002.                 (xfio)->_cnt -= SKBtemp;        \
  1003.                 }
  1004.  
  1005. /*
  1006.  * Get data from buffer and update pointers
  1007.  */
  1008. #define GETDATA(bufptr, xfio, xnbits)                \
  1009.             {                    \
  1010.             register int GTDtemp;            \
  1011.             GTDtemp = (xnbits);            \
  1012.             BUFCHK((xfio),(GTDtemp));        \
  1013.             MOV_BITS((bufptr), (xfio)->_ptr, (GTDtemp)); \
  1014.             SKIP_BITS((xfio),(GTDtemp));        \
  1015.             }
  1016.  
  1017. /*
  1018.  * Put the data in the buffer from the UDA
  1019.  */
  1020. #define PUTDATA(bufptr, xfio, xnbits)                \
  1021.             {                    \
  1022.             register long PTDtemp;            \
  1023.             PTDtemp = (xnbits);            \
  1024.             BUFCHK((xfio),(PTDtemp));        \
  1025.             MOV_BITS((xfio)->_ptr, (bufptr), (PTDtemp)); \
  1026.             SET_BPTR((xfio)->_ptr,            \
  1027.                 INC_BPTR((xfio)->_ptr,(PTDtemp))); \
  1028.             (xfio)->segbits += (PTDtemp);        \
  1029.             (xfio)->_cnt += (PTDtemp);        \
  1030.             }
  1031.  
  1032. /*
  1033.  * Get a small number of bits where it is not justified to call MOVBIT
  1034.  * The resultant bits are left justified in the word.
  1035.  * No checking is done.    POINTERS AND COUNTS ARE NOT INCREMENTED
  1036.  * nbits MUST be <= 64.  When sizeof(long) == 64, 64 bits are always 
  1037.  * returned. When sizeof(long) == 32, 32 bits are always returned.
  1038.  */
  1039. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1040. #define GET_BITS(outword,bufptr,nbits)                          \
  1041.                 {                                               \
  1042.                 register int qzshft;                            \
  1043.                 qzshft = BPBITOFF(bufptr);                      \
  1044.                 SANITYCHK((nbits),GT,64);                       \
  1045.                 SANITYCHK((nbits),LT,1);                        \
  1046.                 if (((qzshft & 07)== 0) && (((nbits) & 07) == 0)) \
  1047.                         {                                       \
  1048.                         char *_op;                              \
  1049.                         char *_bp;                              \
  1050.                         int   _iz;                              \
  1051.                         _bp = BPTR2CP(bufptr);                  \
  1052.                         _op = (char *)&(outword);               \
  1053.                         (outword) = 0;                          \
  1054.                         for (_iz = 0; _iz < (nbits)/8; _iz++)   \
  1055.                                 {                               \
  1056.                                 *_op++ = *_bp++;                \
  1057.                                 }                               \
  1058.                         }                                       \
  1059.                 else                                            \
  1060.                         {                                       \
  1061.                         (outword) = _dshiftl(*BPTR2WP(bufptr),  \
  1062.                                         *(BPTR2WP(bufptr)+1),   \
  1063.                                         qzshft)                 \
  1064.                         & _mask(nbits); /* mask from left */    \
  1065.                         }                    \
  1066.                 }
  1067. #else
  1068. #define GET_BITS(outword,bufptr,nbits)                \
  1069.         {                        \
  1070.         register int qzshft;                \
  1071.         qzshft = BPBITOFF(bufptr);            \
  1072.         SANITYCHK((nbits),GT,64);            \
  1073.         SANITYCHK((nbits),LT,1);            \
  1074.         (outword) = _dshiftl(*BPTR2WP(bufptr),        \
  1075.                     *(BPTR2WP(bufptr)+1),    \
  1076.                     qzshft)            \
  1077.             & _mask(nbits); /* mask from left */    \
  1078.         }
  1079. #endif
  1080.  
  1081. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1082. #define PUT_BITS(bufptr,idata,nbits)                                    \
  1083.         {                                                       \
  1084.         long P_Btmp1, P_Btmp2, *P_Bp;                           \
  1085.         int P_Boff;                                             \
  1086.         P_Boff = BPBITOFF(bufptr);                              \
  1087.         if (((P_Boff & 07) == 0) && (((nbits)&07) == 0))        \
  1088.             {                        \
  1089.             char *P_Bz;                                     \
  1090.             int __i;                    \
  1091.             P_Bz =  BPTR2CP(bufptr);                        \
  1092.             for (__i = 0; __i < (nbits)/8; __i++)           \
  1093.                 *P_Bz++ = ((unsigned long)(idata) >> ((sizeof(long) -(__i+1))*8)) & 0xff; \
  1094.             }                                               \
  1095.                 else                                                    \
  1096.             {                        \
  1097.             P_Bp = BPTR2WP(bufptr);                \
  1098.             if ((P_Boff+(nbits)) <= _BITS_PER_LONG)        \
  1099.                 {                    \
  1100.                 P_Btmp1 = 0;                \
  1101.                 P_Btmp2 = 0;                \
  1102.                 if (P_Boff != 0)            \
  1103.                     P_Btmp1 = (unsigned long)*P_Bp >> \
  1104.                      (_BITS_PER_LONG - P_Boff);    \
  1105.                 if ((P_Boff + (nbits)) != _BITS_PER_LONG) \
  1106.                     P_Btmp2 = *P_Bp << (P_Boff + (nbits)); \
  1107.                 P_Btmp1 = _dshiftl(P_Btmp1, idata, (nbits)); \
  1108.                 *P_Bp = _dshiftl(P_Btmp1, P_Btmp2,    \
  1109.                     _BITS_PER_LONG - (P_Boff + (nbits))); \
  1110.                 }                                               \
  1111.             else                                                    \
  1112.                 {                                               \
  1113.                 P_Btmp1 = (unsigned long)*P_Bp >>               \
  1114.                  (_BITS_PER_LONG - P_Boff);                      \
  1115.                 P_Btmp2 = *(P_Bp + 1) << (P_Boff+(nbits)-_BITS_PER_LONG);\
  1116.                 *P_Bp = _dshiftl(P_Btmp1, (idata), _BITS_PER_LONG-P_Boff);\
  1117.                 P_Btmp1 = _dshiftl(P_Btmp1, (idata), (nbits));  \
  1118.                 *(P_Bp+1) = _dshiftr(P_Btmp1, P_Btmp2,          \
  1119.                     P_Boff + (nbits) - _BITS_PER_LONG);\
  1120.                 }                                               \
  1121.             }                                                   \
  1122.         }
  1123.  
  1124. #else
  1125. /*
  1126.  * PUT_BITS
  1127.  * Put a small number of bits (idata) in a specified place. (bufptr)
  1128.  * input data is left justified in the word.
  1129.  * This works only if the number of bits is less than 64.
  1130.  * No checking is done.    POINTERS AND COUNTS ARE NOT INCREMENTED
  1131.  * This means that it works to put a few bits in place where there
  1132.  * is surrounding data (backpatching)
  1133.  * For 64-bit architectures, we assume idata is a 64-bit word.
  1134.  * For 32-bit architectures, we assume idata is a 32-bit word.
  1135.  */
  1136. #define PUT_BITS(bufptr,idata,nbits)                    \
  1137.         {                            \
  1138.         long P_Btmp1, P_Btmp2, *P_Bp;                \
  1139.         int P_Boff;                        \
  1140.         P_Boff = BPBITOFF(bufptr);                \
  1141.         P_Bp = BPTR2WP(bufptr);                    \
  1142.         if ((P_Boff+(nbits)) <= _BITS_PER_LONG)            \
  1143.             {                        \
  1144.             P_Btmp1 = 0;                    \
  1145.             P_Btmp2 = 0;                    \
  1146.             if (P_Boff != 0)                \
  1147.                 P_Btmp1 = (unsigned long)*P_Bp >>    \
  1148.                  (_BITS_PER_LONG - P_Boff);         \
  1149.             if ((P_Boff + (nbits)) != _BITS_PER_LONG)    \
  1150.                 P_Btmp2 = *P_Bp << (P_Boff + (nbits));    \
  1151.             P_Btmp1 = _dshiftl(P_Btmp1, idata, (nbits));    \
  1152.             *P_Bp = _dshiftl(P_Btmp1, P_Btmp2,        \
  1153.                 _BITS_PER_LONG - (P_Boff + (nbits)));    \
  1154.             }                        \
  1155.         else                            \
  1156.             {                        \
  1157.             P_Btmp1 = (unsigned long)*P_Bp >>        \
  1158.              (_BITS_PER_LONG - P_Boff);            \
  1159.             P_Btmp2 = *(P_Bp + 1) << (P_Boff+(nbits)-_BITS_PER_LONG);\
  1160.             *P_Bp = _dshiftl(P_Btmp1, (idata), _BITS_PER_LONG-P_Boff);\
  1161.             P_Btmp1 = _dshiftl(P_Btmp1, (idata), (nbits));    \
  1162.             *(P_Bp+1) = _dshiftr(P_Btmp1, P_Btmp2,        \
  1163.                     P_Boff + (nbits) - _BITS_PER_LONG);\
  1164.             }                        \
  1165.         }
  1166. #endif
  1167.  
  1168. /*
  1169.  * MOV_BITS
  1170.  *    Move the specified bits from a_a to b_b.
  1171.  */
  1172. #if    defined(__mips) || defined(_SOLARIS) || defined(_LITTLE_ENDIAN)
  1173. #define MOVBIT movbit_
  1174. #define MOVBITZ movbitz_
  1175. #endif
  1176.  
  1177. #ifdef    _ABSOFT
  1178. #define MOVBIT movbit
  1179. #define MOVBITZ movbitz
  1180. #endif
  1181.  
  1182. extern void _memwcpy(long *_s, long *_s0, int _n);
  1183.  
  1184. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1185. #define _MOVEM(to_b, frm_a, nbits)                    \
  1186.             {                        \
  1187.             long long    M_aoff, M_boff;            \
  1188.             M_aoff = BPBITOFF(frm_a);            \
  1189.             M_boff = BPBITOFF(to_b);            \
  1190.             if (((M_aoff & 07) | (M_boff & 07) |        \
  1191.                     (nbits & 07)) == 0 )        \
  1192.                 {                    \
  1193.                 memcpy(BPTR2CP(to_b), BPTR2CP(frm_a), \
  1194.                 (nbits) / 8);                \
  1195.                 }                    \
  1196.             else                        \
  1197.                 {                    \
  1198.                 long long    M_Bits;            \
  1199.                                     \
  1200.                 M_Bits = (nbits);            \
  1201.                 M_aoff = BPBITOFF(frm_a);        \
  1202.                 M_boff = BPBITOFF(to_b);        \
  1203.                 SANITYCHK(M_aoff,GT,_BITS_PER_LONG)    \
  1204.                 SANITYCHK(M_aoff,GT,_BITS_PER_LONG)    \
  1205.                 MOVBITZ(BPTR2WP(frm_a), &M_aoff,    \
  1206.                     &M_Bits, BPTR2WP(to_b), &M_boff);\
  1207.                 }                    \
  1208.             }
  1209. #else
  1210. #define _MOVEM(to_b, frm_a, nbits)                    \
  1211.             {                        \
  1212.             if ((BPBITOFF(frm_a) | BPBITOFF(to_b) |        \
  1213.                     (nbits & 077)) == 0 )        \
  1214.                 {                    \
  1215.                 _memwcpy(BPTR2WP(to_b), BPTR2WP(frm_a), \
  1216.                 (nbits) / _BITS_PER_LONG);        \
  1217.                 }                    \
  1218.             else                        \
  1219.                 {                    \
  1220.                 long    M_aoff, M_boff, M_Bits;        \
  1221.                                     \
  1222.                 M_Bits = (nbits);            \
  1223.                 M_aoff = BPBITOFF(frm_a);        \
  1224.                 M_boff = BPBITOFF(to_b);        \
  1225.                 SANITYCHK(M_aoff,GT,_BITS_PER_LONG)    \
  1226.                 SANITYCHK(M_aoff,GT,_BITS_PER_LONG)    \
  1227.                 MOVBITZ(BPTR2WP(frm_a), &M_aoff,    \
  1228.                     &M_Bits, BPTR2WP(to_b), &M_boff);\
  1229.                 }                    \
  1230.             }
  1231. #endif
  1232.  
  1233. #define MOV_BITS(to_b,frm_a,bits)                    \
  1234.             {                        \
  1235.             SANITYCHK(BPTR2WP(frm_a),LE,(long *)100)    \
  1236.             SANITYCHK(BPTR2WP(to_b),LE,(long *)100)        \
  1237.             _MOVEM(to_b, frm_a, bits);            \
  1238.             }
  1239.  
  1240. /*
  1241.  * Clear the status word.  These macros clear the iosw and ffsw structures.
  1242.  * Note that only the first three words of the ffsw are cleared.  This is
  1243.  * because the fourth word is new in UNICOS 7.0, and for safety is not used.
  1244.  * On machines where _ADDR64 is true (and MIPS), more space is cleared.
  1245.  */
  1246.  
  1247. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1248. #define CLRSTAT(io_sw)        {*(int *)&(io_sw) = 0; io_sw.sw_count=0;}
  1249. #else
  1250. #define CLRSTAT(io_sw)        *(long *)&(io_sw) = 0
  1251. #endif
  1252.  
  1253. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1254. /* Clear through sw_sptr */
  1255. #define CLRFFSTAT(io_sw)                        \
  1256.             {                        \
  1257.             long    *_ptr;                    \
  1258.             _ptr    = (long *)&(io_sw);            \
  1259.             *_ptr++    = 0;                    \
  1260.             *_ptr++    = 0;                    \
  1261.             *_ptr++    = 0;                    \
  1262.             *_ptr++    = 0;                    \
  1263.             *_ptr++    = 0;                    \
  1264.             *_ptr++    = 0;                    \
  1265.             }
  1266. #elif    defined(_ADDR64) 
  1267. #define CLRFFSTAT(io_sw)                        \
  1268.             {                        \
  1269.             long    *_ptr;                    \
  1270.             _ptr    = (long *)&(io_sw);            \
  1271.             *_ptr++    = 0;                    \
  1272.             *_ptr++    = 0;                    \
  1273.             *_ptr++    = 0;                    \
  1274.             *_ptr++    = 0;                    \
  1275.             }
  1276. #else
  1277. #define CLRFFSTAT(io_sw)                        \
  1278.             {                        \
  1279.             long    *_ptr;                    \
  1280.             _ptr    = (long *)&(io_sw);            \
  1281.             *_ptr++    = 0;                    \
  1282.             *_ptr++    = 0;                    \
  1283.             *_ptr++    = 0;                    \
  1284.             }
  1285. #endif
  1286.  
  1287. #if    defined(DEBUG) && !defined(__mips) && !defined(_LITTLE_ENDIAN)
  1288. #define _STATPRINT(trcvar, nstat)                    \
  1289.             {                        \
  1290.             if (FDCTRACE(TRACE_STATUS))            \
  1291.                 {                    \
  1292.                 char _str[128];                \
  1293.                                     \
  1294.                 sprintf(_str,                \
  1295.                     "SETSTAT: %d, at line number %d in file %s\n", \
  1296.                         nstat, __LINE__, __FILE__); \
  1297.                 _xrt_putstr(_str);            \
  1298.                 }                    \
  1299.             }
  1300.  
  1301. #define _ERRPRINT(trcvar, errnum)                    \
  1302.             {                        \
  1303.             if (FDCTRACE(TRACE_STATUS))            \
  1304.                 {                    \
  1305.                 char _str[128];                \
  1306.                                     \
  1307.                 sprintf(_str,                \
  1308.                     "SETERROR: %d, at line number %d in file %s\n", \
  1309.                         errnum, __LINE__, __FILE__); \
  1310.                 _xrt_putstr(_str);            \
  1311.                 }                    \
  1312.             }
  1313. #else
  1314. #define _STATPRINT(trcvar, nstat)
  1315. #define _ERRPRINT(trcvar, errnum)
  1316. #endif
  1317.  
  1318. /*
  1319.  * Set the status field in the status struct.
  1320.  */
  1321. #define _SETSTAT(io_sw,nstat,nbytes)    {                \
  1322.                 (io_sw)->sw_flag = 1;            \
  1323.                 (io_sw)->sw_error = 0;            \
  1324.                 (io_sw)->sw_count = (nbytes);        \
  1325.                 (io_sw)->sw_stat = (nstat);        \
  1326.                 }
  1327.  
  1328. /*
  1329.  * Set the error status.  Always print the error in DEBUG mode
  1330.  */
  1331. #define _SETERROR(io_sw,errnum,nbytes)    {                \
  1332.                 (io_sw)->sw_flag = 1;            \
  1333.                 (io_sw)->sw_error = (errnum);        \
  1334.                 (io_sw)->sw_count = (nbytes);        \
  1335.                 FFSTAT(*io_sw) = FFERR;            \
  1336.                 _ERRPRINT(TRACE_STATUS,errnum);        \
  1337.                 }
  1338.  
  1339. #define SETSTAT(io_sw,nstat,nbytes)    {                \
  1340.                 _SETSTAT(io_sw,nstat,nbytes);        \
  1341.                 _STATPRINT(__fdctrace_enable,nstat);    \
  1342.                 }
  1343.  
  1344. /*
  1345.  * Set the status and return an error.  Always print the status in DEBUG mode
  1346.  */
  1347. #define ERETURN(io_sw,errnum,nbytes)    {                \
  1348.                     _SETERROR(io_sw,errnum,nbytes);    \
  1349.                     return(ERR);            \
  1350.                     }
  1351.  
  1352. #if    !defined(__mips) && !defined(_LITTLE_ENDIAN)
  1353. #define _FFOPEN_ERETURN(_a,_b,_c) ERETURN((_a),(_b),(_c))
  1354. #define _FFOPEN_ERR ERR
  1355. #else
  1356. #define _FFOPEN_ERR (_ffopen_t) -1L
  1357. #define _FFOPEN_ERETURN(_a,_b,_c) { \
  1358.         _SETERROR((_a),(_b),(_c)); \
  1359.         return(_FFOPEN_ERR); }
  1360. #endif
  1361.  
  1362. /*
  1363.  * These are the 'generic' SCC codes.  They are the ones that
  1364.  * are used internally and translated into those for IBM and VMS
  1365.  * Having the FULL code =0 has the advantage if no SCCs need to be
  1366.  * processed.
  1367.  */
  1368. #define SCCUNKN -1    /* This does not translate into a 'real' SCC code */
  1369. #define SCCFULL 0
  1370. #define SCCFRST 1
  1371. #define SCCLAST 2
  1372. #define SCCMIDL 3
  1373.  
  1374. /*
  1375.  * segment control code definitions fr all classes
  1376.  */
  1377. #define SCC_IBM        0    /* IBM type Segment Control code */
  1378. #define SCC_VMS        1    /* VMS type Segment Control code */
  1379. #define SCC_CDC        2    /* CDC type Segment Control code */
  1380. #define SCC_NVE        3    /* CDC type Segment Control code */
  1381.  
  1382. /*
  1383.  * Number of SCC types.  This is for the scc table dimension
  1384.  */
  1385. #define NUM_SCC_TYPES    4    /* IBM, VMS and CDC, and NOS/VE*/
  1386.  
  1387. /*
  1388.  * error codes for FDC parameters while parsing the -F assign attribute.
  1389.  */
  1390. #define FDC_PERR_CLASS    1
  1391. #define FDC_PERR_RFC    2
  1392. #define FDC_PERR_RFCS    3
  1393. #define FDC_PERR_RSZ    4
  1394. #define FDC_PERR_MBS    5
  1395. #define FDC_PERR_MIN    6
  1396. #define FDC_PERR_MAX    7
  1397. #define FDC_PERR_INC    8
  1398. #define FDC_PERR_BAD    9
  1399.  
  1400. #define NUM_PERRS    9
  1401.  
  1402. /*
  1403.  * fddcvrt_u: foreign dataset data conversion descriptor word.
  1404.  *    This word contains fields that describe the users
  1405.  *    request for data conversion.
  1406.  *
  1407.  *
  1408.  *  0                                                              64
  1409.  * /--------+--------+--------+----------------------------------------\
  1410.  * |vers    | bin    | char   |                                        |
  1411.  * |info    | cvrt   | set    |          unused     ...(40 bits)       |
  1412.  * | 8 bits | 8 bits | 8 bits |                                        |
  1413.  * \--------+--------+--------+----------------------------------------/
  1414.  *  ^        ^        ^
  1415.  *  zero     ^        ^
  1416.  *  for      ^        ^
  1417.  *  now      ^        ^
  1418.  *           ^        ^
  1419.  *           ^        ^
  1420.  *           ^        ^
  1421.  *           ^        ^
  1422.  *           ^        ^
  1423.  *           ^        1=ascii
  1424.  *           ^        2=ebcdic
  1425.  *           ^        etc...
  1426.  *           ^
  1427.  *           2=binary - IBM
  1428.  *           3=binary - CDC
  1429.  *           etc..
  1430.  */
  1431. union fddcvrt_u
  1432.     {
  1433.     struct
  1434.         {
  1435.         int    vers:8;        /* version ID, zero for now */
  1436.         int    cvrt:8;        /* numeric conversion code */
  1437.         int    cvch:8;        /* character conversion code */
  1438.         int    cvch_opt:8;    /* text record options */
  1439.         int    unused:32;
  1440.         } fld;
  1441.     unsigned long    wword;
  1442.     };
  1443.  
  1444. /*
  1445.  * spec_u:
  1446.  *
  1447.  *    FFIO specification word.  A sequence of one or more of consecutive
  1448.  *    spec_u words is used to pass FFIO layer parameters to any layer's
  1449.  *    open routine.
  1450.  *
  1451.  *    The first 8 bits of each spec_u word contain the extension bit and the
  1452.  *    class.  The extension bit is set in all but the last spec_u word
  1453.  *    in a spec_u word sequence.
  1454.  *
  1455.  *    The remainder of each word can contain different info depending on
  1456.  *    class.
  1457.  *
  1458.  *    Before changing spec_u, be sure the new structure will maintain
  1459.  *    compatibility between new versions of the asgcmd command and old
  1460.  *    libraries.
  1461.  *
  1462.  *    Starting in UNICOS 7.0, a "standard default sequence" of spec_u words
  1463.  *    is used for most layers.  The sequence generated by layer specification
  1464.  *
  1465.  *            layer.str1.str2:num1:num2:num3:...:numN
  1466.  *
  1467.  *    is:
  1468.  *
  1469.  * Word 0 (hdr):
  1470.  * -------------
  1471.  *  0                                                                   64
  1472.  * /-+-+-----+--------+----+----+--------------------+--------------------\
  1473.  * |e| |class| str1   |str2|          unused                              |
  1474.  * |x| |     |        |    |                                              |
  1475.  * |t| |6-bit| 8-bits |4bit|          44-bits                             |
  1476.  * \-+-+-----+--------+----+----+--------------------+--------------------/
  1477.  *
  1478.  * Words 1..N (info):
  1479.  * ------------------
  1480.  *  0                                                                   64
  1481.  * /-+-+-----+--------+----+----+--------------------+--------------------\
  1482.  * |e|v|class|                        value                               |
  1483.  * |x|a|     |                                                            |
  1484.  * |t|l|6-bit|                        56-bits                             |
  1485.  * \-+-+-----+--------+----+----+--------------------+--------------------/
  1486.  *
  1487.  *
  1488.  * Spec_u word format used for SDS and MR layers:
  1489.  *
  1490.  * Word 0 (fss):
  1491.  * -------------
  1492.  *  0                                                                   64
  1493.  * /-+-+-----+--------+----+----+--------------------+--------------------\
  1494.  * |e| |class| recfmt |styp|    |                min                      |
  1495.  * |x| |     |        |    |    |                                         |
  1496.  * |t| |6-bit| 8-bits |4bit|    |              40-bits                    |
  1497.  * \-+-+-----+--------+----+----+--------------------+--------------------/
  1498.  *
  1499.  *
  1500.  * Spec_u word 0 format used for compatibility between asgcmd and old libraries:
  1501.  *
  1502.  * Word 0 (fld):
  1503.  * -------------
  1504.  *  0                                                                   64
  1505.  * /-+-+-----+--------+----+----+--------------------+--------------------\
  1506.  * |e| |class| recfmt |styp|    |     recsize        |     mbs            |
  1507.  * |x| |     |        |    |    |                    |                    |
  1508.  * |t| |6-bit| 8-bits |4bit|    |     20-bits        |     20-bits        |
  1509.  * \-+-+-----+--------+----+----+--------------------+--------------------/
  1510.  *
  1511.  * Spec_u word 0 format used by new assign parser
  1512.  *
  1513.  * Word 0 (fld):
  1514.  * -------------
  1515.  *  0                                                                   64
  1516.  * /-+-+-----+--------+----+----+--------------------+--------------------\
  1517.  * |e| |class| info        |     recsize        |     mbs            |
  1518.  * |x| |     |             |    |                    |                    |
  1519.  * |t| |6-bit| 12-bits     |    |     20-bits        |     20-bits        |
  1520.  * \-+-+-----+--------+----+----+--------------------+--------------------/
  1521.  */
  1522. #if    defined(_CRAY) || defined(__mips) || defined(_LITTLE_ENDIAN)
  1523. /*
  1524.    #ifndef    uint64
  1525.    #define uint64 unsigned long long
  1526.    #endif
  1527.    #ifndef    int64
  1528.    #define int64 long long
  1529.    #endif
  1530. */
  1531. typedef uint64 _spect;    /* 64-bit unsigned integer */
  1532. #else
  1533. typedef unsigned _spect;
  1534. #endif
  1535. union spec_u
  1536.     {
  1537.     struct
  1538.         {
  1539.         _spect ext    :1;    /* ext bit is on if not end of spec */
  1540.         _spect        :1;
  1541. #ifndef    __cplusplus
  1542.         _spect class    :6;    /* ffio CLASS */
  1543. #else
  1544.         _spect classsp    :6;    /* ffio CLASS */
  1545. #endif
  1546.         _spect str1    :8;    /* string parameter 1 */
  1547.         _spect str2    :4;    /* string parameter 2 */
  1548.         } hdr;
  1549.     struct
  1550.         {
  1551.         _spect ext    :1;    /* set to 1 if not end of spec */
  1552.         _spect valid    :1;    /* set to 1 if this param was passed */
  1553. #ifndef    __cplusplus
  1554.         _spect class    :6;    /* ffio CLASS */
  1555. #else
  1556.         _spect classsp :6;    /* ffio CLASS */
  1557. #endif
  1558. #if    defined(_WORD32) && !defined(__mips) && !defined(_LITTLE_ENDIAN)
  1559.         unsigned quan;        /* numeric parameter value */
  1560. #else
  1561.         _spect quan    :56;    /* numeric parameter value */
  1562. #endif
  1563.         } info;
  1564.     struct
  1565.         {
  1566.         _spect ext    :1;    /* ext bit is on if not end of spec */
  1567.         _spect        :1;
  1568. #ifndef    __cplusplus
  1569.         _spect class    :6;    /* ffio CLASS */
  1570. #else
  1571.         _spect classsp    :6;    /* ffio CLASS */
  1572. #endif
  1573.         _spect recfmt    :8;    /* This is the record format */
  1574.         _spect subtype    :4;    /* record format subtype. */
  1575. #if    defined(_WORD32)  && !defined(__mips) && !defined(_LITTLE_ENDIAN)
  1576.         unsigned min;
  1577. #else
  1578.         _spect        :4;
  1579.         _spect min    :40;
  1580. #endif
  1581.         } fss;
  1582.     struct
  1583.         {
  1584.         _spect ext    :1;    /* ext bit is on if not end of spec */
  1585.         _spect unused1    :1;
  1586. #ifndef    __cplusplus
  1587.         _spect class    :6;    /* ffio CLASS */
  1588. #else
  1589.         _spect cpasssp    :6;    /* ffio CLASS */
  1590. #endif
  1591.         _spect recfmt    :8;    /* This is the record format */
  1592.         _spect subtype    :4;    /* record format subtype. */
  1593.         _spect        :4;
  1594.         _spect recsize    :20;
  1595.         _spect mbs    :20;
  1596.         } fld;
  1597.     struct
  1598.         {
  1599.         _spect ext    :1;    /* ext bit is on if not end of spec */
  1600.         _spect unused1    :1;
  1601. #ifndef    __cplusplus
  1602.         _spect class    :6;    /* ffio CLASS */
  1603. #else
  1604.         _spect cpasssp    :6;    /* ffio CLASS */
  1605. #endif
  1606.         _spect info1    :24;    /* This contains non-numeric info */
  1607.         _spect info2    :32;    /* This contains more non-numeric info */
  1608.         } class_info;
  1609. #if    defined(_CRAY) || defined(__mips) || defined(_LITTLE_ENDIAN)
  1610.     _spect wword;    
  1611. #elif    defined(_WORD32)
  1612.     unsigned long long wword;
  1613. #else
  1614. #error "THIS CASE IS NOT HANDLED"
  1615. #endif
  1616.     };
  1617.  
  1618. /*
  1619.  * Find the next start of spec..
  1620.  *    Skip the extension words.
  1621.  */
  1622. #define NEXT_SPEC(nxtspec)    { nxtspec = _next_spec(nxtspec); }
  1623. #include <cray/mtlock.h>
  1624.  
  1625. /*
  1626.  *    Global open information packet.  This structure contains information
  1627.  *    intended to be shared by all FFIO layers in a chain.
  1628.  */
  1629. struct gl_o_inf {
  1630.     int        version;    /* version number for gl_o_inf    */
  1631.                     /* structure.  Is 0 in 8.1+ libraries */
  1632.     enum {
  1633.       OT_FORTRAN=1,
  1634.       OT_USER1=2,
  1635.       OT_USER2=4,
  1636.       OT_USER3=8,
  1637.       OT_USER4=16,
  1638.       OT_USER5=32,
  1639.       OT_USER6=64,
  1640.       OT_USER7=128,
  1641.       OT_USER8=256,
  1642.       OT_USER9=512,
  1643.       OT_SSIO=1024
  1644.     }        open_type;    /* code for type of open    */
  1645.  
  1646.     union {
  1647.      struct {            /* for Fortran files ...    */
  1648.       unum_t    unum;        /* unit number (-1 if unknown)    */
  1649.       unsigned    is_seq:1;    /* 1 iff access='sequential'    */
  1650.       unsigned    is_fmt:1;    /* 1 iff form='formatted'    */
  1651.       long        reclen;        /* 0 or RECL= value        */
  1652.      } fort;    
  1653.      int        pad_a[15];    /* pad for future expansion    */
  1654.     } u;
  1655.  
  1656.     unsigned    alreadyopen:1;    /* 1 iff file is already opened and */
  1657.                     /* "fd" contains file descriptor.   */
  1658.                     /* Used only by _gsys_open and         */
  1659.                     /* _bmx_open.                */
  1660.  
  1661.  
  1662.     int        fd;        /* file descriptor of already-open  */
  1663.                     /* tape file.                */
  1664.  
  1665.     int        depth;        /* FFIO layer depth (1 == top level)*/
  1666.  
  1667.     struct assign_info_s
  1668.             *aip;        /* assign info, or NULL    */
  1669.  
  1670.     int        pad_b[4];    /* pad for future expansion */
  1671.  
  1672.     int64        user[2];    /* reserved for user layers */
  1673.     int64        site[2];    /* reserved for site layers */
  1674.  
  1675. };
  1676.  
  1677. /*
  1678.  * This structure defines the function pointers that comprise the standard
  1679.  * interface that is used between layers of the FDC process.
  1680.  */
  1681. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1682. typedef struct fdinfo * _ffopen_t;
  1683. typedef off_t        _ffseek_t;
  1684. #else
  1685. typedef int        _ffopen_t;
  1686. typedef int        _ffseek_t;
  1687. #endif
  1688.  
  1689. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1690. #define    ___(A) A
  1691. #else
  1692. #define    ___(A) ()
  1693. #endif
  1694.  
  1695. struct xtr_s
  1696.     {
  1697.  
  1698.     /* Specific open processing for the file type */
  1699.     _ffopen_t (* openrtn) ___((const char *_Name, int _Flags, mode_t _Mode, struct fdinfo *_Fio, union spec_u *_Spec, struct ffsw *_Retstat, long _Cbits, int _Cblks, struct gl_o_inf *_Oinf));
  1700.  
  1701.     /* Read one block/record of data packed */
  1702.     ssize_t (* readrtn) ___((struct fdinfo *_Fio, bitptr _Bufptr, size_t _Nbytes, struct ffsw *_Retstat, int _Fulp, int *_Ubc));
  1703.  
  1704.     /* Read one block/record of data async */
  1705.     ssize_t (* readartn) ___((struct fdinfo *_Fio, bitptr _Bufptr, size_t _Nbytes, struct ffsw *_Retstat, int _Fulp, int *_Ubc));
  1706.  
  1707.     /* Read one block/record of data 1 char/wd */
  1708.     ssize_t (* readcrtn) ___((struct fdinfo *fio, bitptr _Bufptr, size_t _Nbytes, struct ffsw *_Restat, int _Fulp));
  1709.  
  1710.     /* Write one block/record of data packed */
  1711.     ssize_t (* writertn) ___((struct fdinfo *_Fio, bitptr _Bufptr, size_t _Nbytes, struct ffsw *_Retstat, int _Fulp, int *_Ubc));
  1712.  
  1713.     /* Write one block/record of data async */
  1714.     ssize_t (* writeartn) ___((struct fdinfo *_Fio, bitptr _Bufptr, size_t _Nbytes, struct ffsw *_Retstat, int _Fulp, int *_Ubc));
  1715.  
  1716.     /* Write one block/record of data 1 char/wd */
  1717.     ssize_t (* writecrtn) ___((struct fdinfo *_Fio, bitptr _Bufptr, size_t _Nbytes, struct ffsw *_Restat, int _Fulp));
  1718.  
  1719.     /* Do any special cleanup and close file */
  1720.     int (* closertn) ___((struct fdinfo *_Fio, struct ffsw *_Retstat));
  1721.  
  1722.     /* Flush the buffers */
  1723.     int (* flushrtn) ___((struct fdinfo *_Fio, struct ffsw *_Retstat));
  1724.  
  1725.     /* endfile routine, not always meaningful */
  1726.     int (* weofrtn) ___((struct fdinfo *_Fio, struct ffsw *_Retstat));
  1727.  
  1728.     /* end of data routine "the REAL end" */
  1729.     int (* weodrtn) ___((struct fdinfo *_Fio, struct ffsw *_Retstat));
  1730.  
  1731.     /* seek on foreign file?? */
  1732.     _ffseek_t (* seekrtn) ___((struct fdinfo *_Fio, off_t _Pos, int whence, struct ffsw *_Retstat));
  1733.  
  1734.     /* backspace routine */
  1735.     int (* backrtn) ___((struct fdinfo *_Fio, struct ffsw *_Retstat));
  1736.  
  1737.     /* positioning routine */
  1738.     _ffseek_t (* posrtn) ___((struct fdinfo *_Fio, int _Cmd, void *_Arg, int _Len, struct ffsw *_Stat));
  1739.  
  1740.     /* listio routine */
  1741.     int (* listiortn) ___((int _Cmd, struct fflistreq *_List, int _Nent, struct ffsw *_Stat)); 
  1742.  
  1743.     int (* fcntlrtn) ___((struct fdinfo *_Fio, int _Cmd, void *_Arg, struct ffsw *_Stat));    /* fcntl routine */
  1744.     };
  1745.  
  1746. /* 
  1747.  * Remove definition of ___
  1748.  */
  1749. #undef    ___
  1750.  
  1751. /*
  1752.  * the fdinfo block is a sort of 'DSP' for FDC.  It contains all of the
  1753.  * state information used by the various routines.
  1754.  */
  1755. struct fdinfo
  1756.     {
  1757.     long    magic;        /* magic number for ID */
  1758.     int    realfd;        /* Our real file descriptor number */
  1759.                 /* this is only used by layers that have */
  1760.                 /* either private implementations, or */
  1761.                 /* 'real' file descriptors. */
  1762.     struct fdinfo *fioptr;    /* Pointer to fdinfo block for next */
  1763.                 /* lower level. */
  1764.     struct fdinfo *parptr;    /* Pointer to fdinfo block for parent layer */
  1765.  
  1766.     struct stat *lstp;    /* Pointer to result of last stat/ffstat call */
  1767.                 /* If null, none has been done */
  1768.     long    opn_flags;    /* Flags used in open call */
  1769. /*
  1770.  *    info about blocks and records
  1771.  */
  1772.     int    subtype;    /* record subtype (block type for CDC) */
  1773.     int64    maxrecsize;    /* max record size in BITS */
  1774.     int64    maxblksize;    /* Maximum Block Size (MBS) in BITS */
  1775. #ifndef    __cplusplus
  1776.     int    class;        /* record translation class */
  1777. #else
  1778.     int    classfdinfo;    /* record translation class */
  1779. #endif
  1780.     int    rtype;        /* Record type, as defined above */
  1781. /*
  1782.  *    Counters.  These are the counts of data and such in the buffer(s).
  1783.  *    Note:  All counts are kept and passed in bits.
  1784.  */
  1785.     int64    recbits;    /* total number of bits in logical record */
  1786.                 /* This is only valid after a partial read */
  1787.                 /* or write.  It is reset at each EOR/EOF */
  1788.     long    segbits;    /* number of bits left in segment */
  1789.                 /* This always indicates the amount */
  1790.                 /* of 'clear' data to be processed. */
  1791.                 /* on write, this is the number of bits */
  1792.                 /* already in the buffer, on read, the */
  1793.                 /* number left in the buffer */
  1794.     int    scc;        /* segment control code */
  1795.     int    lastscc;    /* segment control code for prev. segment. */
  1796.     int64    last_recbits;    /* record length of last record in BITS */
  1797.                 /* This is used differently in various layers */
  1798. /*
  1799.  *    Buffer info
  1800.  */
  1801.     bitptr    _base;        /* BIT pointer */
  1802.     bitptr    _ptr;        /* BIT pointer to next data in buffer */
  1803.     long    _cnt;        /* BIT count. Bits left in buffer on read*/
  1804.                 /*          Bits accumulated on write */
  1805.     long    _ffbufsiz;    /* BIT size of buffer */
  1806.  
  1807. /*
  1808.  *    Flags
  1809.  */
  1810.     int rwflag;        /* 4 for position, 2 for write, 1 for read */
  1811.                 /* This tells what the last operation was, */
  1812.                 /* nothing about open mode(s) */
  1813.     unsigned atbod:1;    /* _TRUE if at beginning of data */
  1814.     unsigned ateor:1;    /* _TRUE if at end of record */
  1815.     unsigned ateof:1;    /* _TRUE if EOF was last op (read or write) */
  1816.     unsigned ateod:1;    /* _TRUE if EOD was last op (read or write) */
  1817.     unsigned can_listio:1;    /* _TRUE if layer can handle listio */
  1818.     unsigned lock:1;    /* _TRUE if ffxxx routines need to lock */
  1819.     unsigned reg_lock:1;    /* _TRUE if ffxxx rtns use regular locks */
  1820.     unsigned free_lock:1;    /* _TRUE if a lock layer needs to free */
  1821.     plock_t *lock_word;    /* layers request that we use their lock */
  1822.     int    rsv6;        /* reserved for CRI */
  1823. /*
  1824.  *    Function pointers (!)
  1825.  */
  1826.     struct xtr_s xr;    /* pointers to routines that do the work. */
  1827. /*
  1828.  *    record type specific information
  1829.  */
  1830.     void    *lyr_info;    /* private layer info block ptr */
  1831.     };
  1832.  
  1833. /* extern declarations */
  1834.  
  1835. extern int __fdctrace_enable;    /* debugging flags */
  1836.  
  1837. extern int _scc_tab[NUM_SCC_TYPES][4];
  1838.  
  1839. /*
  1840.  *    These prototypes are for internal functions which a user may not
  1841.  *    use by default.
  1842.  */
  1843. #if    defined(__mips) || defined(_CRAY) || defined(_LITTLE_ENDIAN)
  1844. typedef int64 _nparmtype;    /* type of numeric parameters */
  1845. #else
  1846. typedef int _nparmtype;
  1847. #endif
  1848. extern _nparmtype _ff_nparm_getv (union spec_u *spec, int parnum, int *isvalid);
  1849. extern int _ff_nparm_getcnt (union spec_u *spec);
  1850. extern union spec_u *_next_spec(union spec_u *sp);
  1851.  
  1852. extern _ffopen_t _ffopen (const char *name, int flags, mode_t mode,
  1853.     union spec_u *spek, struct ffsw *stat, long cbits, int cblks,
  1854.     struct fdinfo *pa_fio, struct gl_o_inf *oinf);
  1855.  
  1856. extern int _ffopensg(const char *name, int flags, mode_t mode,
  1857.     long cbits, int cblks, struct ffsw *stat,
  1858.     const char *cspec, struct gl_o_inf *oinf);
  1859.  
  1860. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1861. extern int _ff_fdinfo_to_int(_ffopen_t fd, struct ffsw *pstat);
  1862. #else
  1863. #define    _ff_fdinfo_to_int(fd, pstat)    ((int)(fd))
  1864. #endif
  1865.  
  1866. #endif    /* _LIB_INTERNAL */
  1867.  
  1868. #if    defined(__mips) || defined(_LITTLE_ENDIAN)
  1869. __BEGIN_DECLS
  1870. extern int ffassign (char *cmd);
  1871. extern int ffbksp (int _Fd);
  1872. extern int ffclose (int _Fd);
  1873. extern ssize_t ffread (int _Fd, void *_Buf, size_t _Nb);
  1874. extern ssize_t ffwrite (int _Fd, const void *_Buf, size_t _Nb );
  1875. extern off_t ffseek (int _Fd, off_t _Pos, int _Whence );
  1876. extern int ffweof (int _Fd);
  1877. extern int ffweod (int _Fd);
  1878. extern int ffopens (const char *_Name, int _Oflag, mode_t _Mode, long _Cbits,
  1879.     int _Cblks, struct ffsw *_Stat, const char *_Str);
  1880. extern int fffcntl (int _Fd, int _Cmd, void *_Arg, struct ffsw *_Stat);
  1881. extern off_t ffpos (int _Fd, int _Cmd, void *_Arg, int _Len,
  1882.     struct ffsw *_Stat);
  1883. extern int ffflush (int _Fd, struct ffsw *_Stat);
  1884. extern char *ffstrerror(int _Errnum);
  1885. __END_DECLS
  1886. #else
  1887. #include <cray/clibinc_config.h>
  1888. #if    !defined(_CRAYT3E) && _CRAYLIBS_RELEASE < 3000
  1889. #define _USE_OLD_PROTOTYPE 1
  1890. #endif
  1891. __BEGIN_DECLS
  1892. extern int ffbksp (int _Fd, ...);
  1893. extern int ffclose (int _Fd, ...);
  1894. extern int fffcntl (int _Fd, int _Cmd, ...);
  1895. extern int ffflush (int _Fd, ...);
  1896. extern int fflistio (int _Cmd, struct fflistreq *_List, int _Nent, ...);
  1897. extern int ffopens (const char *_Name, int _Oflag, int _Mode, long _Cbits,
  1898.     ... );
  1899. extern int ffpos (int _Fd, int _Cmd, long *_Arg, int _Len,
  1900.     struct ffsw *_Stat);
  1901. extern char *ffstrerror(int _Errnum);
  1902. #if    _USE_OLD_PROTOTYPE
  1903. extern int ffread (int _Fd, char *_Buf, int _Nb, ...);
  1904. #else
  1905. extern int ffread (int _Fd, void *_Buf, size_t _Nb, ...);
  1906. #endif
  1907. extern int ffreada (int _Fd, char *_Buf, int _Nb, struct ffsw *_Stat, ...);
  1908. extern int ffreadc (int _Fd, char *_Buf, int _Nb, ...);
  1909. #if    _USE_OLD_PROTOTYPE
  1910. extern int ffseek (int _Fd, int _Pos, int _Whence, ...);
  1911. #else
  1912. extern int ffseek (int _Fd, off_t _Pos, int _Whence, ...);
  1913. #endif
  1914. extern int ffsetsp (int _Fd, ...);
  1915. extern int ffweod (int _Fd, ...);
  1916. extern int ffweof (int _Fd, ...);
  1917. #if    _USE_OLD_PROTOTYPE
  1918. extern int ffwrite (int _Fd, char *_Buf, int _Nb, ...);
  1919. #else
  1920. extern int ffwrite (int _Fd, const void *_Buf, size_t _Nb, ...);
  1921. #endif
  1922. extern int ffwritea (int _Fd, char *_Buf, int _Nb, struct ffsw *_Stat, ...);
  1923. extern int ffwritec (int _Fd, char *_Buf, int _Nb, ...);
  1924. __END_DECLS
  1925. #endif
  1926. __BEGIN_DECLS
  1927. extern int ffbkspf (int _Fd, struct ffsw *_Stat);
  1928. extern int ffopen (const char *_Name, int _Oflag, ...);
  1929. extern int ffopenf (const char *_Name, int _Oflag, mode_t _Mode, long _Cbits,
  1930.  int _Cblks, struct ffsw *_Pstat);
  1931. extern int ffiolock (int _fd, struct ffsw *_Stat);
  1932. extern int ffiounlock (int _fd, struct ffsw *_Stat);
  1933. extern int ffclosef (int _Fd, struct ffsw *_Stat);
  1934. extern int ffweoff (int _Fd, struct ffsw *_Stat);
  1935. extern int ffweodf (int _Fd, struct ffsw *_Stat);
  1936. extern off_t ffseekf (int _Fd, off_t _Pos, int _Whence, struct ffsw *_Stat);
  1937. extern ssize_t ffreadf (int _Fd, void *_Buf, size_t _Nb, struct ffsw *_stat, int _Fulp, int *_Ubc);
  1938.  
  1939. extern ssize_t ffwritef (int _Fd, const void *_Buf, size_t _Nb, struct ffsw *_stat, int _Fulp, int *_Ubc);
  1940. __END_DECLS
  1941.  
  1942. #endif /* !_FFIO_H */
  1943.